package com.net.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "Servlet",urlPatterns = {"servlet"})
public class Servlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
       //服务器端获取浏览器端提交的数据
        String  userName = request.getParameter(s:"userName");
        String userPassword = request.getParameter(s:"userPassword");

        //验证数据合法性
        if(userName.equals("aaa"))&&userPassword.equals("bbb"){
            request.getRequestDispatcher(s:"index.html").forward(request,response);//如果正确转到index网页
        }else{
          /*  request.getRequestDispatcher(s:"error.html").forward(request,response);//错了的话跳到这里*/
            response.getWriter().print("<script>alter('登录信息错误')；window.history.back();</script>");
        }

    }//核心处理代码


    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
